class Solution
{
public:
    bool checkDistances(string s, vector<int> &distance)
    {
        vector<int> thisDis(26, -1);
        int n = s.size();
        for (int i = 0; i < s.size(); ++i)
        {
            if (thisDis[s[i] - 'a'] == -1)
            {
                thisDis[s[i] - 'a'] = i;
            }
            else
            {
                thisDis[s[i] - 'a'] = i - 1 - thisDis[s[i] - 'a'];
            }
        }
        for (int i = 0; i < 26; ++i)
        {
            if (thisDis[i] != -1 && thisDis[i] != distance[i])
            {
                return false;
            }
        }
        return true;
    }
};